package com.swinginwind.flexutils.components.dataGridClasses
{
	/**
	 * @author jimmy
	 * @E-mail: swinginwind@gmail.com
	 * @version 1.0.0
	 * 创建时间：2013-5-13 上午10:19:57
	 * 
	 */
	import com.swinginwind.flexutils.components.CenterCheckBox;
	
	import flash.events.MouseEvent;
	
	import mx.binding.utils.BindingUtils;
	import mx.controls.CheckBox;
	import mx.controls.DataGrid;
	import mx.events.DataGridEvent;

	public class CheckBoxHeaderRenderer extends CenterCheckBox
	{
		
		
		
		public function CheckBoxHeaderRenderer()
		{
			super();
			//addEventListener("click", clickHandler);
		}
		private var _data:CheckBoxHeaderColumn;
		override public function get data():Object
		{
			return _data;
		}
		
		override public function set data(value:Object):void
		{
			_data = value as CheckBoxHeaderColumn;
			DataGrid(listData.owner).addEventListener(DataGridEvent.HEADER_RELEASE, sortEventHandler);
			selected = _data.selected;
			this.label = _data.headerText;
			BindingUtils.bindProperty(this, "enabled", _data, "enable");
			
		}
		
		
		private function sortEventHandler(event:DataGridEvent):void
		{
			if (event.itemRenderer == this)
				event.preventDefault();
		}
		override protected function clickHandler(event:MouseEvent):void
		{
			if(_data.enable)
			{
				super.clickHandler(event);
				data.selected = selected;
				data.dispatchEvent(event);
			}
		}
		
		
		
	}
}